<%- include('../layout') %>

<% contentFor('body') { %>
<% currentPath = '/users' %>
<div class="container-fluid">
  <div class="d-flex justify-content-between align-items-center mb-4">
    <h2>编辑用户</h2>
    <a href="/admin/users" class="btn btn-secondary">返回列表</a>
  </div>
  
  <div class="card">
    <div class="card-body">
      <form action="/admin/users/edit/<%= user.id %>" method="post">
        <div class="mb-3">
          <label for="username" class="form-label">用户名 *</label>
          <input type="text" class="form-control" id="username" name="username" value="<%= user.username %>" required>
        </div>
        <div class="mb-3">
          <label for="email" class="form-label">邮箱 *</label>
          <input type="email" class="form-control" id="email" name="email" value="<%= user.email %>" required>
        </div>
        <div class="mb-3">
          <label for="password" class="form-label">密码（留空表示不修改）</label>
          <input type="password" class="form-control" id="password" name="password">
        </div>
        <div class="mb-3">
          <label for="membershipLevelId" class="form-label">会员等级</label>
          <select class="form-select" id="membershipLevelId" name="membershipLevelId">
            <% membershipLevels.forEach(level => { %>
            <option value="<%= level.id %>" <%= user.membershipLevelId === level.id ? 'selected' : '' %>><%= level.name %></option>
            <% }); %>
          </select>
        </div>
        <div class="mb-3">
          <label for="avatar" class="form-label">头像URL</label>
          <input type="text" class="form-control" id="avatar" name="avatar" value="<%= user.avatar || '' %>">
        </div>
        <div class="mb-3">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="isAdmin" <%= user.isAdmin ? 'checked' : '' %>> 管理员权限
          </label>
        </div>
        <div class="d-flex gap-2">
          <button type="submit" class="btn btn-primary">保存</button>
          <a href="/admin/users" class="btn btn-secondary">取消</a>
        </div>
      </form>
    </div>
  </div>
</div>
<% } %>